﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CustomsSystem.Model;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Data.Common;
using System.Collections.Generic;
using Maticsoft.DBUtility;

namespace CustomsSystem.DAL
{
    public partial class ClientService
    {
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CustomsSystem.Model.Client GetModel(string ClientName, string PassWord)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,ClientName,PassWord,Company_ID from Cu_Client ");
            strSql.Append(" where ClientName=@ClientName and PassWord=@PassWord");
            SqlParameter[] parameters = {
						new SqlParameter("@ClientName", SqlDbType.VarChar,20),
					new SqlParameter("@PassWord", SqlDbType.VarChar,32)
                                        };
            parameters[0].Value = ClientName;
            parameters[1].Value = PassWord;

            CustomsSystem.Model.Client model = new CustomsSystem.Model.Client();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ClientName"] != null)
                {
                    model.ClientName = ds.Tables[0].Rows[0]["ClientName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PassWord"] != null)
                {
                    model.PassWord = ds.Tables[0].Rows[0]["PassWord"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Company_ID"] != null)
                {
                    model.Company_ID =Convert.ToInt32(ds.Tables[0].Rows[0]["Company_ID"].ToString());
                }

                return model;
            }
            else
            {
                return null;
            }
        }
    }
}
